package com.focus.xyz.other.pages.pingan;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import com.focus.xyz.core.utils.Constants;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/7/1.
 */
public class AppTracePage extends BasePage {
    private Action action;
    private WebDriver driver;

    /*
    * 根据证单号查询报价
    * */
    @FindBy(xpath = "//select[@id='apply.voucherType']")
    private WebElement voucherType;
    @FindBy(xpath = "//input[@ng-model='apply.voucherNo']")
    private WebElement voucherNo;
    @FindBy(xpath = "//button[contains(text(),'查询')]")
    private WebElement voucherSearch;
    @FindBy(xpath = "//table/tbody[@class='ng-scope']")
    private WebElement resultTab;

    public AppTracePage(WebDriver driver, Action action) {
        super(driver, action);
        this.action = action;
        this.driver = driver;
        PageFactory.initElements(driver,this);
    }


    public String searchAppFee(String voucherNo) throws Exception{
        String appFee = null;
        action.select(voucherType,"子询价单号");
        action.inputText(this.voucherNo,voucherNo);
        action.click(voucherSearch);
        action.waitForAjax();
        action.pause(1000l);
        List<WebElement> rows = resultTab.findElements(By.tagName(Constants.TAG_TR));
        if(rows!=null&&rows.size()>0){
            for(WebElement r:rows){
                WebElement td2 = r.findElement(By.xpath("td[2]/a"));
                if(voucherNo.equals(td2.getText().trim())){
                    appFee = r.findElement(By.xpath("td[8]/div")).getText().trim();
                    break;
                }
            }
        }
        return appFee;
    }




}
